cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(my_cuda_ops LANGUAGES CXX CUDA)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置 CUDA 相关选项
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_ARCHITECTURES "90a")

# 设置 CUTLASS 路径
set(CUTLASS_ROOT_DIR ${CMAKE_SOURCE_DIR}/cutlass)
set(CUTLASS_INC ${CUTLASS_ROOT_DIR}/include)
set(CUTLASS_UTIL_INC ${CUTLASS_ROOT_DIR}/tools/util/include)

# 查找所有 CUDA 源文件
file(GLOB CUDA_SOURCES "src/*.cu")

# 添加共享库
add_library(my_cuda_ops SHARED ${CUDA_SOURCES})

# 设置库属性
set_target_properties(my_cuda_ops PROPERTIES
    CUDA_EXTENSIONS OFF
    POSITION_INDEPENDENT_CODE ON
    CUDA_SEPARABLE_COMPILATION ON
)

# 包含目录
target_include_directories(my_cuda_ops PRIVATE
    ${CUTLASS_INC}
    ${CUTLASS_UTIL_INC}
)

# 链接库
target_link_libraries(my_cuda_ops PRIVATE
    cudart
    cuda
)

# 添加编译选项
target_compile_options(my_cuda_ops PRIVATE
    $<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr>
)

install(TARGETS my_cuda_ops DESTINATION /usr/local/lib)
